<?php
class PNUserListUserArray extends PNObjectExArray {
  function PNUserListUserArray($init=null, $where='')
  {
    $this->PNObject();

    $this->_objType       = 'user_data';
    $this->_objField      = 'id';
    $this->_objPath       = 'form';
    $this->_objGroup      = 'uda_uid';
//    $this->_objColumnExArray = array('count_topic' => 'COUNT(tpc_cr_uid)');

    $this->_objJoin[]     = array ( 'join_table'  =>  'users',
                            'join_field'          =>  array('uid','uname','email'),
                            'object_field_name'   =>  array('uid','uname','email'),
                            'compare_field_table' =>  'uda_uid',
                            'compare_field_join'  =>  'uid');
/*
    $this->_objJoin[]     = array ( 'join_table'  =>  'innoforum_topics',
                            'join_field'          =>  array('cr_uid'),
                            'object_field_name'   =>  array('cr_uid'),
                            'compare_field_table' =>  'uda_uid',
                            'compare_field_join'  =>  'cr_uid');
*/
    $this->_init($init, $where);
  }

 function genSort(){
      return 'ORDER BY uname ASC';
  }

  function genFilter(){
    $type_search   = FormUtil::getPassedValue ('type_search', false);
    $keyword  = FormUtil::getPassedValue ('keyword', false);

    $wheres = array();

    $where[] = 'pn_uda_propid = 1';

    //filter by keyword
    if ($keyword && $type_search){
      switch($type_search){
        case 'uname': $where[] = "pn_uname LIKE '%". $keyword ."%'"; break;
        case 'uda_uname': $where[] = "pn_uda_value LIKE '%". $keyword ."%'"; break;
        case 'pre_uname': $where[] = "pn_uname LIKE '". $keyword ."%'"; break;
        case 'number': $where[] = " pn_uname Like '0%'
                                      or
                                     pn_uname Like '1%'
                                      or
                                     pn_uname Like '2%'
                                      or
                                     pn_uname Like '3%'
                                      or
                                     pn_uname Like '4%'
                                      or
                                     pn_uname Like '5%'
                                      or
                                     pn_uname Like '6%'
                                      or
                                     pn_uname Like '7%'
                                      or
                                     pn_uname Like '8%'
                                      or
                                     pn_uname Like '9%'"; break;
      }
      $wheres = implode(' AND ', $where) ;
    }else {
      $wheres = 'pn_uda_propid = 1';
    }
    return $wheres;

  }

/*
  function genFilter(){
    $wheres = 'pn_uda_propid = 1';
    return $wheres;
  }
*/
}